var base=getApp();
Page({
  data: {
    is_anonymous: 0,
    content: "",
    gid: 0,
    oid:0,
    mylist:[],
    url: base.path.url,
    star:5,
  },
  onLoad:function(e){
    var that = this;
    var gid = parseInt(e.gid);
    var oid = parseInt(e.oid);
    this.data.gid = gid;
    this.data.oid = oid;
    that.orderList();
  },
  orderList: function () {
    var that = this; 
    wx.request({
      url: base.path.api + 'Member.GetUserOrdersDetail',
      data: {
        md5key: base.user.session_key,
        aid: base.user.aid,
        oid: that.data.oid
      },
      async: false,
      method: "POST",
      header: base.user.header,
      success: function (response) {
        var result = response.data;
        var mylist = {};
        if (result.ret == 200) {
          var mylist = result.data;
          var valname = "";
          for (var j = 0; j < mylist.val_name.length; j++) {
            valname += mylist.val_name[j].attr_name + "：" + mylist.val_name[j].val_name + " "
          }
          mylist.detail = mylist.goods_name + "," + valname;
          that.setData({
            mylist: mylist,
          })

        }

      },
      fail: function (reg) {


      }
    })
  },
  bindStar: function (e) {
    var star = e.currentTarget.dataset.star;
    this.setData({
      star:star
    });
  },
  onShareAppMessage: function () {
    return {
      title: base.user.shareTitle,
      desc: base.user.shareDesc,
      path: '/pages/index/index',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  checkboxChange: function (e) {
    var that=this;
    var is_anonymous=parseInt(e.detail.value);
    if(is_anonymous==0){
      is_anonymous=1;
    }else{
      is_anonymous=0;
    }
    that.data.is_anonymous = is_anonymous;
  },
  bindComment:function(e){
    this.data.content = e.detail.value
  },
  bindSubmit: function(){
    var that = this;
    var gid = that.data.gid;
    var oid = that.data.oid;
    var content = that.data.content;
    var is_anonymous = that.data.is_anonymous;
    wx.request({
      url: base.path.api + 'Goods.UserComment',
      data: {
        md5key: base.user.session_key,
        gid: gid,
        order_id: oid,
        star:that.data.star,
        content: content,
        is_anonymous: is_anonymous
      },
      method: "POST",
      header: base.user.header,
      success: function (response) {
        var result = response.data;
        if (result.ret == 200) {
          wx.showModal({
            showCancel: false,
            content: '评价成功',
            success: function (res) {
              if (res.confirm) {
                wx.switchTab({
                  url: '/pages/user/user',
                })
              }
            }
          })
        }
      }
    })
  }

})